package tcu.iot.gasmanage.api;

import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import tcu.iot.gasmanage.common.Result;
import tcu.iot.gasmanage.common.utils.QuerySwitchUtils;
import tcu.iot.gasmanage.entity.person.Person;
import tcu.iot.gasmanage.entity.person.PersonQuery;
import tcu.iot.gasmanage.service.PersonService;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Api(value = "人员管理控制器")
@RestController
@RequestMapping("/waiters")
@CrossOrigin
public class PersonController {
    @Resource
    private PersonService personService;

    @ApiOperation(value = "/list", notes = "获取所有人员管理数据")
    @GetMapping(value = "/list", produces = "application/json;UTF-8")
    public Result getAllPerson(HttpServletRequest request) {
        PersonQuery personQuery = JSON.parseObject(QuerySwitchUtils.QuerySwitch(request.getQueryString()), PersonQuery.class);

        return personService.getAllPerson(personQuery);
    }

    @ApiOperation(value = "/create", notes = "添加人员信息")
    @PostMapping("/create")
    public Result AddPerson(@RequestBody Person RequestPerson) {
        return personService.AddPerson(RequestPerson);
    }

    @ApiOperation(value = "/delete", notes = "删除人员信息")
    @PostMapping(value = "/delete")
    public Result DeletePerson(@RequestParam(value = "id") int id) {
        return personService.DeletePerson(id);
    }

    @ApiOperation(value = "/update", notes = "修改人员信息")
    @PostMapping(value = "/update")
    public Result UpdatePerson(@RequestBody Person RequestPerson) {
        return personService.UpdatePerson(RequestPerson);
    }

    @ApiOperation(value = "/options", notes = "获取数据库选项信息")
    @PostMapping(value = "/options")
    public Result FindOptions() {
        return personService.FindOptions();
    }
}

